package com.bamboo.tool.entity;

import com.alibaba.fastjson.JSONObject;
import lombok.Data;
import lombok.ToString;
import org.apache.commons.lang3.StringUtils;

import java.util.*;

@Data
@ToString
public class ApiClass {
    private String id;
    /**
     * 类名
     */
    private String className = StringUtils.EMPTY;
    /**
     * 模块名
     */
    private String moduleName = StringUtils.EMPTY;
    /**
     * 项目名称
     */
    private String projectName;
    /**
     * 项目id
     */
    private String projectId;
    /**
     * 描述集合
     */
    private Map<String, String> desc = new HashMap<>();
    /**
     * 类完整路径
     */
    private String classPath;
    /**
     * 项目url
     */
    private String poolUrl;
    /**
     * 类url
     */
    private String classUrl ;
    /**
     * 方法集合
     */
    private List<ApiMethod> methods = new ArrayList<>();
    /**
     *
     */
    private AnnotationInfoSetting setting;

    /**
     * class 其它信息
     */
    private ClassOtherInfo classOtherInfo = new ClassOtherInfo();
    /**
     * class 持久化
     */
    private ClassPersistenceInfo persistence = new ClassPersistenceInfo();

    public String toInsertSql(Integer projectInfoId) {
        StringBuilder sql = new StringBuilder();
        sql.append("INSERT INTO bamboo_class (id,class_name, model_name,  class_path, project_id,setting_id,other_info,description,persistence) VALUES (");
        sql.append("'").append(id).append("',");
        sql.append("'").append(className).append("',");
        sql.append("'").append(moduleName).append("',");
        sql.append("'").append(classPath).append("',");
        sql.append("'").append(projectInfoId).append("',");
        sql.append("'").append(setting.getId()).append("',");
        sql.append("'").append(JSONObject.toJSON(classOtherInfo)).append("',");
        sql.append("'").append(JSONObject.toJSON(desc)).append("',");
        sql.append("'").append(JSONObject.toJSON(persistence)).append("'");
        sql.append(");");
        return sql.toString();
    }

}
